-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[unitaryHACK] Create a Pytorch simulator #1225 #1360
Conversation
Thanks @Slimane33! Looking forward to reviewing this, simply let us know via a comment in the PR when this is ready for review (or, alternatively, if you have any questions).
Hmm, it seems that the Autograd interface is not compatible with the PyTorch device. This might be because the device test suite is defaulting to Instead, we would like to use
In this particular example @Slimane33, could you do? return torch.diag([p, torch.conj(p)]) |
How can we change that? The test suite works for
It does not work because return torch.diag(torch.tensor([[p, 0], [0, torch.conj(p)]], dtype=C_DTYPE, device=device)) |
… into pytorch-device
… into pytorch-device
@josh146 @antalszava Ready to override and merge from my side. |
🎉 |
Thanks @co9olguy ! and Great efforts from @Slimane33 as well. |
Context:
Create a quantum simulator with PyTorch.
Description of the Change:
A new device
default.qubit.torch
is created. It allows all quantum operations and measurements to be performed within the PyTorch worlkflow.Benefits:
It allows end-to-end GPU computation and integration of quantum circuits with the torch interface of Pennylane. A fully working example can be found here: https://colab.research.google.com/drive/1Xb_-l3TIOZhbDw6K9jO34oDgDqzs3o7V?usp=sharing
All the gates implemented with Tensorflow have been reimplemented and seem to work.
Remaining work:
pl-device-test --device default.qubit.torch --shots None
I get the following error
Since it seems to be a fundamental error of incompatibility between
torch.dtype
andnumpy.dtype
, I don't understand why I am still able to normally run the circuit.Writing the appropriate unit test
test_default_qubit_torch.py
Check formatting
Possible drawbacks:
More maintenance, torch operations are more different of numpy ones than tensorflow ones are.
Autograd in Pytorch is very sensitive. For example this formulation of RZ gate works
while this one doesn't
Related GitHub Issues:
#1225
This is a collective contribution from: @arshpreetsingh, @PCesteban, @artm88, @charmerDark, @mkasmi, @Slimane33